<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>科室管理</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>
<body>
<Style>
.hwcitem{
	margin-top:15px;
	padding-left:50px;
}
</Style>
	<script type="text/javascript">
		$(function() {
			//打开添加窗口
			$("#hwc-addDept").linkbutton({
				onClick : function() {

					$("#hwcwin-add").window({
						'title' : "添加科室"
					});
					$("#hwcform-add").form("clear");
					$("#hwcwin-add").window("open");

				}
			});
			//添加科室
			$("#hwcbtn-ok").linkbutton({
				onClick : function(){
					var title = $('#hwcwin-add').window("options").title;
					var url = (title == '添加科室' ? 'addNewTbdepartment' : 'editDepartment');
					
					$('#hwcform-add').form('submit',{
						url : url,
						onSubmit : function(){
							//验证
							return $(this).form("validate");
						},
					success : function(data){
						var json = eval("("+data+")");
						$.messager.alert("提示",json.reason);
						$("#hwcwin-add").window('close');
						$("#hwc_department").datagrid("reload");
						$(this).form("clear");
						
						}
					});
				}
			});
			
			//修改科室
			$("#hwc-editDept").linkbutton(
					{
						onClick : function() {
							var rows = $("#hwc_department").datagrid(
									"getSelections");
							if (rows.length == 1) {
								$("#hwcwin-add").window({
									'title' : "修改科室"
								});
								$("#hwcwin-add").window("open");
								//初始化表单
								var departmentno = rows[0].departmentNo;
								$.getJSON("findTbdepartmentById", {
									"departmentno" : departmentno
								}, function(data) {
									$("#hwcform-add").form("load", data);
								});
							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ rows.length + "条!");
							}

						}
					});
			//删除科室
			$("#hwc-deleteDept").linkbutton({
				onClick : function(){
				$.messager.confirm("提示","您确定要删除该科室吗？",
				function(v){
						if (v) {
						//获取所有选中的编号
							var rows = $("#hwc_department").datagrid("getSelections");
						//将编号保存到数组中
						var arr = [];
						for (var i = 0; i < rows.length; i++){
							arr.push(rows[i].departmentNo);
							}
						//用form提交
						$('<form>').form('submit',{
							url : 'deleteTbdepartment',
							onSubmit : function(param) {
								param.list = arr;
							},
							success : function(data) {
							var json = eval("("+ data+ ")");
							$.messager.alert("提示","删除成功！");
							$("#hwc_department").datagrid("reload");

								}	
							});
						}
					});
				}
			});
			//显示全部
			$("#hwc-reloadDept").linkbutton({
				onClick : function() {
					$("#hwc_department").datagrid({
						url : 'queryByDepartmentPage',
						method : 'get'
					});
				}
			});
		});
	</script>
	<table id="hwc_department" class="easyui-datagrid"
		data-options="url:'queryByDepartmentPage',
		fitColumns:true,
			fit:true,
			pagination: true,
			pageSize: 5,
			pageList: [5, 10, 15, 20],
			rownumbers: true,
			toolbar: '#hwc-tb',
			border:false
	">
		<thead>
			<tr>
				<th data-options="field:'departmentNo',width:'20%',checkbox:true">科室编号</th>
				<th data-options="field:'departmentName',width:'39%'">科室名称</th>
				<th data-options="field:'address',width:'59%'">科室地址</th>
			</tr>
		</thead>
	</table>
	<!-- 工具栏 -->
	<div id="hwc-tb">
		<a id="hwc-addDept" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">添加科室</a> <a
			id="hwc-editDept" class="easyui-linkbutton"
			data-options="iconCls:'icon-edit',plain:true">修改科室</a> <a
			id="hwc-deleteDept" class="easyui-linkbutton"
			data-options="iconCls:'icon-cancel',plain:true">删除科室</a> <a
			id="hwc-reloadDept" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">全部科室</a> <input
			id="hwc-ss" style="width: 200px"></input>
		<div id="hwc-mm" style="width: 120px">
			<div data-options="name:'departmentName'">部门名称</div>
			<div data-options="name:'address'">部门地址</div>
		</div>
		<script>
			$('#hwc-ss').searchbox({
				searcher : function(value, name) {
					
					$("#hwc_department").datagrid({
						
	 					url : name == 'departmentName' ? 'queryDnameByPage': 'findByDepartmentAddressPage', 
						method : 'post',
						queryParams : {
							
							department : value
						
						},
						onLoadSuccess:function(){
							
							var t = $("#hwc_department").datagrid("getRows");
							var d=t[0];
							if(d == null){
								$.messager.alert("提示","不存在该关键字的记录！");

							}
							
							}});
							$(this).searchbox('setValue','');
							},
							menu : '#hwc-mm',
							prompt : '搜索',	
					});
			
		</script>
	</div>

	<!--  添加/修改窗口-->
	<div id="hwcwin-add" class="easyui-window" title="添加科室"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true"
		style="width: 400px; height: 200px; padding: 5px;">
		<div class="easyui-layout" data-options="fit:true">
		
			<div data-options="region:'center'" style="padding: 10px">
				<form id="hwcform-add" method="post">
					<div class="hwcitem"  style="display:none">
						<input name="departmentNo" class="easyui-textbox"
							data-options="label: '科室ID', width: 250">
					</div>
					
					<div class="hwcitem"">
						<input name="departmentName" class="easyui-textbox"
							data-options="label: '科室名称:', width: 250, required:true">
					</div>

					<div class="hwcitem">
						<input name="address" class="easyui-textbox"
							data-options="label: '科室地址:', width: 250, required:true">
					</div>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
			
				<a id="hwcbtn-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">确定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#hwcwin-add').window('close');" onclick="">取消</a>
			</div>
		</div>
	</div>
</body>
</html>